package bm.com.framework.common.resp;

import bm.com.framework.common.config.EnumCode;
import lombok.Data;

import java.io.Serializable;

@Data
public class Result<T> implements Serializable {
    private static final long serialVersionUID = 1L;

    private int code= EnumCode.CODE_SUCCESS;

    private String msg = "操作成功";

    private T data = null;

    /**
     * 返回错误信息
     * @param code
     * @param msg
     * @return
     */
    public Result<T> error(int code,String msg){
        this.code = code;
        this.msg = msg;
        return this;
    }

    /**
     * 返回错误信息
     * @param msg
     * @return
     */
    public Result<T> error(String msg){
        this.code = EnumCode.CODE_ERROR;
        this.msg = msg;
        return this;
    }

    /**
     * 返回成功信息
     * @param code
     * @param msg
     * @param data
     * @return
     */
    public Result<T> ok(int code,String msg,T data){
        this.code = code;
        this.msg = msg;
        this.data = data;
        return this;
    }

    /**
     * 返回成功信息
     * @param msg
     * @param data
     * @return
     */
    public Result<T> ok(String msg,T data){
        this.msg = msg;
        this.data = data;
        return this;
    }

    /**
     * 返回成功信息
     * @param data
     * @return
     */
    public Result<T> ok(T data){
        this.data = data;
        return this;
    }

}
